-- instance
-- Created by chengb
-- 地牢格子：副本

return {
    restoreGrid = function(grid, info)
        if not info or not info.instance_id then
            return;
        end

        grid.instanceId = info.instance_id;
    end,

    -- 收集上下文
    collectContext = function(grid)
        local ret = {};

        ret.instance_id = grid.instanceId;

        return ret;
    end,

    -- 自动战斗
    autoFight = function(grid)
        local pos = grid:getPos();
        local instance = grid.instanceId;
        if DungeonTentM.isTentInstance(instance) and not grid:canHit() then
            return false;
        end

        -- BOSS层的流浪者帐篷，忽略
        if BossTentM.isHaveBossTent() then
            return false;
        end

        -- 尝试进入副本
        if not DungeonInstanceM.canStartInstance(instance) then
            -- 不满足进入条件
            return false;
        end

        -- 进入副本
        return DungeonActionM.go("start_instance", pos, instance);
    end
};
